﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using EasyDentalMail.View;

namespace EasyDentalMail.DAO
{
    public class SqlConnect
    {
        private static string connString = System.Configuration.ConfigurationManager.ConnectionStrings["edsConn"].ToString();
        public static void AddCalendarID()
        {
            try
            {
                
                using (SqlConnection conn = new SqlConnection(connString))
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = MontarAlter();
                    cmd.Connection = conn;
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao cadastrar GOOGLECALENDAR TABLE", ex);
            }
        }

        private static string MontarAlter()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("if not exists (select * from sysobjects where name='GOOGLECALENDAR' and xtype='U') ");
            sb.Append("BEGIN ");
            sb.Append("CREATE TABLE [dbo].[GOOGLECALENDAR]( " );
            sb.Append("[ID] [int] IDENTITY(1,1) NOT NULL, ");
            sb.Append("[ID_PRESTADOR] [int] NOT NULL, ");
            sb.Append("[ID_UNIDADE] [int] NOT NULL, ");
            sb.Append("[DATA] [datetime] NOT NULL, ");
            sb.Append("[HORAINICIO] [int] NOT NULL, ");
            sb.Append("[CALENDARID] [varchar](50) NOT NULL ");
            sb.Append("CONSTRAINT [PK_GOOGLECALENDAR] PRIMARY KEY CLUSTERED( ");
            sb.Append("[ID] ASC) ");
            sb.Append(") ON [PRIMARY] ");
            sb.Append("END");
            return sb.ToString();
        }
    }
}
